//
//  ViewController.m
//  MasonryDeom
//
//  Created by MyMac on 15/10/22.
//  Copyright © 2015年 tongfang. All rights reserved.
//

#import "ViewController.h"
#import <Masonry/Masonry.h>
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //Masonry的设置思想是设置相对于父视图上下左右的距离，跟autoLayout的设置思想相似
    //make可操作的位置有left，top，right，bottom，leading，trailing，width，height，centerX，centerY，baseline(底部线)等
    //两个常用api
    //1.equalTo：设置相对于父视图的标准线，比如设置相对于父视图左边或右边
    //2.mas_equalTo：设置子视图的大小，位置的具体数据，比如直接设置子视图大小（不需要相对于父视图设置）或者直接设置自视图的中心点
    
    
    UIView *superview =self.view;
    
    UIView *view1 = [UIView new];
    view1.translatesAutoresizingMaskIntoConstraints = NO;
    view1.backgroundColor = [UIColor greenColor];
    [superview addSubview:view1];//先要添加到父视图才能再添加约束
    UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10);
    
    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(superview.mas_top).with.offset(padding.top); //表示与父视图的mas_top(顶部位置)相距padding.top的距离
        make.left.equalTo(superview.mas_left).with.offset(padding.left);
        make.bottom.equalTo(superview.mas_bottom).with.offset(-padding.bottom);
        make.right.equalTo(superview.mas_right).with.offset(-padding.right);
        //make.left.greaterThanOrEqualTo(@30);//view1的左边缘小于过了superview的左边缘30
    }];
   
    
    
    
    UIView*v2=[UIView new];
    v2.backgroundColor=[UIColor redColor];
    [view1 addSubview:v2];
    [v2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(view1).with.insets(padding);//v2于父视图的边缘间隔是padding
    }];
    
   
    
    UIView*v3=[UIView new];
    v3.backgroundColor=[UIColor yellowColor];
    [v2 addSubview:v3];
    [v3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(v2.center.x);//v3的中心x
        make.centerY.mas_equalTo(v2.center.y);//v3的中心y
        make.size.mas_equalTo(CGSizeMake(150, 150));//v3的大小
    }];
    
    
    UIView*v4=[UIView new];
    v4.backgroundColor=[UIColor orangeColor];
    [v3 addSubview:v4];
    [v4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leadingMargin.equalTo(v3.mas_leadingMargin);//与v3左对齐
        make.top.equalTo(v3.mas_top).with.offset(10);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
